712B - Memory and Trident - CodeForces Solution


implementation strings *1100

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    vector<int> arr;
    string s;
    cin>>s;
    if(s.length()%2!=0){
        cout<<"-1";
        return 0;
    }
    int r=0,u=0,l=0,d=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='R'){
            r++;
        }
        else if(s[i]=='U'){
            u++;
        }
        else if(s[i]=='L'){
            l++;
        }
        else{
            d++;
        }
    }
    // cout<<r<<l<<u<<d;
    if(r==l && u==d){
        cout<<"0";
    }
    else{
        int h=abs(r-l);
        int v=abs(u-d);
        if((h+v)%2!=0){
            cout<<"-1";
        }
        else{
            cout<<(h+v)/2;
        }
    }
}
  			 		  			 	    		   				 		


Comments

Submit
0 Comments
More Questions

1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading
1180A - Alex and a Rhombus
445A - DZY Loves Chessboard
1372A - Omkar and Completion
159D - Palindrome pairs
981B - Businessmen Problems
1668A - Direction Change
1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards
897A - Scarborough Fair
1433B - Yet Another Bookshelf
1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth